package com.mall.shopping.services;

import com.mall.shopping.IContentService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.converter.ContentConverter;
import com.mall.shopping.dal.entitys.PanelContent;
import com.mall.shopping.dal.persistence.PanelContentMapper;
import com.mall.shopping.dto.NavListResponse;
import com.mall.shopping.dto.PanelContentDto;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.List;

/**
 * @author hsp
 * @date 2021/5/24 14:10
 */
@Service
@org.springframework.stereotype.Service
public class IContentServiceImpl implements IContentService {
    @Autowired
    PanelContentMapper panelContentMapper;
    @Autowired
    ContentConverter contentConverter;
    @Override
    public NavListResponse queryNavList() {
        Example example = new Example(PanelContent.class);
        example.setOrderByClause("sort_order"); //order by sort_order
        example.createCriteria().andEqualTo("panelId",0).andEqualTo("type",0);
        List<PanelContent> panelContents = panelContentMapper.selectByExample(example);
        List<PanelContentDto> panelContentDtos = new ArrayList<>();
        for (PanelContent panelContent : panelContents) {

            PanelContentDto panelContentDto = contentConverter.panelContent2Dto(panelContent);
            panelContentDtos.add(panelContentDto);

        }
        NavListResponse navListResponse = new NavListResponse();
        navListResponse.setPannelContentDtos(panelContentDtos);
        navListResponse.setCode(ShoppingRetCode.SUCCESS.getCode());
        navListResponse.setMsg(ShoppingRetCode.SUCCESS.getMessage());

        return navListResponse;
    }
}
